package cn.ctodb.mall.goods.service.mapper;

import cn.ctodb.mall.goods.domain.*;
import cn.ctodb.mall.goods.service.dto.GoodsDTO;

import org.mapstruct.*;
import java.util.List;

/**
 * Mapper for the entity Goods and its DTO GoodsDTO.
 */
@Mapper(componentModel = "spring", uses = {CategoryMapper.class, BrandMapper.class, GoodsTypeMapper.class, })
public interface GoodsMapper {

    @Mapping(source = "category.id", target = "categoryId")
    @Mapping(source = "brand.id", target = "brandId")
    @Mapping(source = "goodsType.id", target = "goodsTypeId")
    GoodsDTO goodsToGoodsDTO(Goods goods);

    List<GoodsDTO> goodsToGoodsDTOs(List<Goods> goods);

    @Mapping(source = "categoryId", target = "category")
    @Mapping(source = "brandId", target = "brand")
    @Mapping(source = "goodsTypeId", target = "goodsType")
    Goods goodsDTOToGoods(GoodsDTO goodsDTO);

    List<Goods> goodsDTOsToGoods(List<GoodsDTO> goodsDTOs);
    /**
     * generating the fromId for all mappers if the databaseType is sql, as the class has relationship to it might need it, instead of
     * creating a new attribute to know if the entity has any relationship from some other entity
     *
     * @param id id of the entity
     * @return the entity instance
     */
     
    default Goods goodsFromId(Long id) {
        if (id == null) {
            return null;
        }
        Goods goods = new Goods();
        goods.setId(id);
        return goods;
    }
    

}
